package com.sunday.aomi.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.event.EventBus;
import com.sunday.common.event.ExitApp;
import com.sunday.common.utils.CacheUtils;
import com.sunday.common.utils.Constants;
import com.sunday.common.utils.SharePerferenceUtils;
import com.sunday.common.widgets.UIAlertView;
import com.sunday.aomi.R;
import com.sunday.aomi.http.ApiClient;
import com.sunday.aomi.ui.common.MainActivity;
import com.sunday.aomi.ui.common.WebViewActivity;
import com.sunday.aomi.ui.login.SetPwdActivity;
import com.sunday.aomi.ui.login.ShopLoginActivity;
import com.sunday.member.constv.ConstValue;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 刘涛 on 2017/5/27.
 */

public class SettingActivity extends BaseActivity {

    @Bind(R.id.menu_clear_cash)
    TextView menuClearCash;
    @Bind(R.id.title)
    TextView title;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        title.setText("设置");
        menuClearCash.setText("清理缓存  （"+ CacheUtils.getTotalCacheSize(mContext)+"）");
    }

    @OnClick({R.id.menu_clear_cash,R.id.btn_logout,R.id.menu_set_pwd,R.id.menu_about_us})
    void onClick(View v){
        switch (v.getId()){
            case R.id.menu_clear_cash:
                CacheUtils.clearAllCache(mContext);
                menuClearCash.setText("清理缓存  （"+CacheUtils.getTotalCacheSize(mContext)+"）");
                break;
            case R.id.btn_logout:
                showLogoutDialog();
                break;
            case R.id.menu_set_pwd:
                intent=new Intent(mContext, SetPwdActivity.class);
                startActivity(intent);
                break;
            case R.id.menu_about_us:
             intent=new Intent(mContext, WebViewActivity.class);
                String url= ApiClient.ZONE_URL+"about_us";
                intent.putExtra("url",url);
                intent.putExtra("title","关于我们");
                startActivity(intent);
                break;
        }
    }

    private void showLogoutDialog(){
        final UIAlertView delDialog = new UIAlertView(mContext, "温馨提示", "退出登录？",
                "取消", "确定");
        delDialog.setClicklistener(new UIAlertView.ClickListenerInterface() {
                                       @Override
                                       public void doLeft() {
                                           delDialog.dismiss();
                                       }

                                       @Override
                                       public void doRight() {
                                           logOut();
                                           SharePerferenceUtils.getIns(mContext).removeKey("oAuth");
                                           SharePerferenceUtils.getIns(mContext).removeKey(Constants.IS_LOGIN);
                                           EventBus.getDefault().post(new ExitApp());
                                           intent = new Intent(mContext,ShopLoginActivity.class);
                                           startActivity(intent);
                                           finish();
                                       }
                                   }
        );
        delDialog.show();
    }

    private void logOut(){

    }

}
